What is swagger-schema-official?
The swagger-schema-official npm package provides the official Swagger (OpenAPI) 2.0 schema definitions. It allows developers to validate and work with Swagger 2.0 specifications in their applications.
What are swagger-schema-official's main functionalities?
Schema Validation
This feature allows you to validate a Swagger 2.0 document against the official Swagger schema using a JSON schema validator like Ajv.
const swaggerSchema = require('swagger-schema-official');
const Ajv = require('ajv');
const ajv = new Ajv();
const validate = ajv.compile(swaggerSchema);
const swaggerDoc = { /* your Swagger 2.0 document */ };
const valid = validate(swaggerDoc);
if (!valid) console.log(validate.errors);
Schema Reference
This feature provides direct access to the Swagger 2.0 schema definitions, which can be used for various purposes such as validation, documentation, or tooling.
const swaggerSchema = require('swagger-schema-official');
console.log(swaggerSchema);
Other packages similar to swagger-schema-official
swagger-parser
swagger-parser is a powerful library for parsing, validating, and dereferencing Swagger (OpenAPI) documents. It supports both Swagger 2.0 and OpenAPI 3.0, making it more versatile than swagger-schema-official, which is limited to Swagger 2.0.
openapi-schema-validator
openapi-schema-validator is a library for validating OpenAPI 3.0 schemas. While it does not support Swagger 2.0, it is useful for developers working with the newer OpenAPI 3.0 standard.
swagger-tools
swagger-tools provides a suite of tools for working with Swagger 2.0 documents, including validation, routing, and middleware for Express.js. It offers more functionality than swagger-schema-official, which is focused solely on schema definitions.
Swagger Specification JSON Schemas
This is only JSON Schema file for Swagger version 2.0. Download and Install it via NPM or Bower.
Install via NPM
npm install --save swagger-schema-official
Install 1.2 version via NPM
npm install --save swagger-schema-official@1.2.0
Install via Bower
bower install --save swagger-schema
License
MIT